how to solve sam and substrings

welcome to shbcf.ru